package demo.service.Impl;

import demo.service.UserService;

import java.io.BufferedReader;
import java.io.FileReader;
import java.util.HashMap;
import java.util.Map;

public class UserServiceImpl implements UserService {

    @Override
    public Boolean login(String userName, String passWord) {

        Map<String, String> map = new HashMap<>();

        try (
                FileReader fileReader = new FileReader("demo18\\src\\c.txt");
                BufferedReader bufferedReader = new BufferedReader(fileReader);
        ){

            String len;
            while ((len=bufferedReader.readLine())!=null){
                String[] strings = len.split("=");
                if (strings!=null)
                    map.put(strings[0],strings[1]);
            }

            for (Map.Entry<String, String> entry : map.entrySet()) {
                String k = entry.getKey();
                String v = entry.getValue();
                if (userName.equals(k) && passWord.equals(v)) {
                    return true;
                }
            }

        } catch (Exception e) {
            throw new RuntimeException(e);
        }

        return false;

    }




}
